package gui;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashSet;
import java.util.Set;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import etc.Parser;

import towers.TowerTemplate;

public class ShoppingPane extends JPanel {
	private Selection selection;
	private Set<TowerTemplate> templates;

	public ShoppingPane(Selection selection) {
		super(new GridLayout(2,2));
		this.selection = selection;
		this.setPreferredSize(new Dimension(200,200));
		
		inittemplates();
		
		for (TowerTemplate t: templates) {
			TowerButton b = new TowerButton(t);
			b.addActionListener(b);
			add(b);
		}
	}
	
	private void inittemplates() {
		templates = Parser.getTowers();
	}
	
	class TowerButton extends JButton implements ActionListener {
		private TowerTemplate t;
		
		public TowerButton(TowerTemplate t) {
			this.t = t;
			this.setIcon(t.icon);
		}

		@Override
		public void actionPerformed(ActionEvent arg0) {
			selection.set(t);
		}
	}
}
